package com.t235.gc.collector.controller;

import com.t235.gc.AjaxResult;
import com.t235.gc.collector.service.*;
import com.t235.gc.entity.HomeRecyclingDetailOrder;
import com.t235.gc.entity.Recyclers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/recyclers")
@Api
public class CollectorController {
    @Resource
    private RecyclersService recyclersService;
    @Resource
    private GarbageReadmeterRecordService garbageReadmeterRecordService;
    @Resource
    private HomeRecyclingOrderService homeRecyclingOrderService;
    @Resource
    private DeviceService deviceService;
    @Resource
    private HomeRecyclingDetailOrderService homeRecyclingDetailOrderService;
    /**
     * 回收员登录
     * @param userAccount
     * @param passWord
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userAccount" ,value = "上门回收员账号"),
            @ApiImplicitParam(name = "passWord" ,value = "上门回收员密码")
    })

    @RequestMapping("/login")
    public AjaxResult RecyclersLogin(String userAccount, String passWord){
        Recyclers recyclers = recyclersService.selectByRecyclers(userAccount,passWord);
        if(recyclers !=null){
            return AjaxResult.success(recyclers);
        }
        return AjaxResult.error("用户名或者密码错误");
    }

    /**
     * 箱体回收统计
     * @param recyclersId
     * @return
     */
    @ApiOperation("箱体回收统计")
    @ApiImplicitParam(name = "recyclersId" ,value = "上门回收员ID")
    @RequestMapping("/recyclersStatistical")
    public AjaxResult RecyclersStatistical(String recyclersId){
        return AjaxResult.success(garbageReadmeterRecordService.RecyclersStatistical(recyclersId));
    }
    @ApiOperation("回收员查看订单详细信息")
    @ApiImplicitParam(name = "orderId" ,value = "homeRecyclingOrder 订单ID")
    @RequestMapping("/selectOrder")
    public AjaxResult selectOrder(String orderId){
        List<HomeRecyclingDetailOrder> homeRecyclingDetailOrders = homeRecyclingDetailOrderService.selectOrder(orderId);
        if(homeRecyclingDetailOrders!=null){
            return AjaxResult.success(homeRecyclingDetailOrders);
        }
        return AjaxResult.error();
    }
    @ApiOperation("回收员添加物品详细信息")
    @ApiImplicitParam(name = "orderId" ,value = "homeRecyclingOrder 订单ID")
    @RequestMapping("/addOrder")
    public AjaxResult addOrder(String orderId, HomeRecyclingDetailOrder order){
        order.setOrderid(Long.valueOf(orderId));
        return AjaxResult.success(homeRecyclingDetailOrderService.insert(order));
    }
    @ApiOperation("上门回收统计，上门回收")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderStatus" ,value = "订单状态:1.预约中 2.已接单 3.审核中 4.已驳回 5.已完成 6.已取消"),
            @ApiImplicitParam(name = "recyclersId" ,value = "上门回收员ID"),
            @ApiImplicitParam(name = "date" ,value = "本日 day，本周 week ，本月 month ")
    })
    @RequestMapping("/visitRecyclersStatistical")
    public AjaxResult visitRecyclersStatistical(String orderStatus, String recyclersId, String date){
        return AjaxResult.success(homeRecyclingOrderService.visitRecyclersStatistical(orderStatus,recyclersId,date));
    }
    /**
     * 设备管理
     */
    @ApiOperation("查询满溢设备管理")
    @RequestMapping("/equipment")
    public AjaxResult equipment(){
        return AjaxResult.success(deviceService.equipment());
    }
}
